<!DOCTYPE html>
<html>
<head>
    <title>固定定位</title>
    <style>
        body{
            height: 3000px;
        }
        .nav{
            position: sticky;
            top: 0;
            background-color: salmon;
            height: 100px;
            width: 500px;
            margin: 200px auto;
        }
    </style>
</head>
<body>
    <div class="nav"></div>
</body>
</html>